﻿@using BeautySalon.Models.TableModel;
@model UserAdmin

@{
    ViewBag.Title = "编辑用户密码";
    Layout = "~/Views/Shared/_LayoutOtherMaster.cshtml";
}



<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="L_UserName" class="layui-form-label">
                    <span class="x-red">*</span>登录名
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="L_UserName" readonly="readonly" name="UserName" required="" lay-verify="" autocomplete="off" class="layui-input" value="@Model.UserName">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_Password" class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_Password" name="Password" required="" lay-verify="pass" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
            </div>
            <div class="layui-form-item">
                <label for="L_RePassword" class="layui-form-label">
                    <span class="x-red">*</span>确认密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_RePassword" name="RePassword" required="" lay-verify="repass" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_RePassword" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="updatePwd" lay-submit="">编辑密码</button>
                <input type="hidden" name="UserId" value="@Model.UserId"/>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer', 'jquery'],
        function () {
            var form = layui.form;
            var layer = layui.layer;

            //自定义验证规则
            form.verify({
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                repass: function (value) {
                    if ($('#L_Password').val() != $('#L_RePassword').val()) {
                        return '两次密码不一致';
                    }
                }
            });

            //监听提交
            form.on('submit(updatePwd)',
                function (data) {
                    console.log("编辑密码")
                    layer.load(3);
                    $.ajax({
                        url: '/UserAdmin/EditUserPass',
                        type: 'post',
                        data: data.field,
                        dataType: 'json',
                        success: function (data) {
                            console.log(data);
                            console.log(data.Msg);
                            console.log(data.ResultType);
                            var sMsg = data.Msg;
                            var sFail = data.Msg;
                            if (data.ResultType == 1) {
                                // 更新成功
                                layer.alert(sMsg, { icon: 6 }, function () {
                                    xadmin.close();
                                });
                            }
                            else if (data.ResultType == 2) {
                                // 更新失败
                                layer.alert(sMsg, { icon: 2 });
                            }
                            else {
                                // 更新失败
                                layer.alert(sMsg, { icon: 2 });
                            }
                        },
                        error: function (err) {
                            layer.alert("密码更新失败", { icon: 2 });
                        }
                    });

                    layer.closeAll("loading");
                    return false;
                });

        });</script>